package com.linghang.wusthelpercompetition.mapper;

import com.linghang.wusthelpercompetition.entity.ResponsePost;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ResponsePostMapper{
    /**
     * 新增回复信息
     * @param responsePost
     */
    @Insert("insert into response_post (student_id , cid , status , response , end_update_time) " +
            "values (#{studentId}, #{cid}, #{status}, #{response}, #{endUpdateTime}, #{contactInformation})")
    void insert(ResponsePost responsePost);

    /**
     * 删除回复信息_物理删除
     * @param rid
     */
    @Delete("delete from response_post where rid = #{rid}")
    void deleteById(Long rid);

    /**
     * 根据id查询回复信息
     * @param rid
     * @return ResponsePost
     */
    @Select("select * from response_post where rid = #{rid} ")
    ResponsePost selectById(Long rid);

    /**
     * 根据用户id查询回复信息
     * @param studentId
     * @return List<ResponsePost>
     */
    @Select("select * from response_post where student_id = #{studentId} order by end_update_time desc")
    List<ResponsePost> selectListByStudentId(String studentId);

    /**
     * 根据帖子id查询回复信息
     * @param cid
     * @return List<ResponsePost>
     */
    @Select("select * from response_post where cid = #{cid} order by end_update_time desc")
    List<ResponsePost> selectListByCid(Long cid);

    /**
     * 根据帖子id查询回复信息_物理删除
     * @param cid
     */
    @Select("select * from response_post where cid = #{cid} and student_id = #{studentId}")
    public ResponsePost getResponsePostByCidAndStudentId(Long cid , String studentId);


    /**
     * 更新回复信息
     * @param responsePost
     * @return
     */
    void updateById(ResponsePost responsePost);


    @Select("select * from response_post where student_id = #{studentId}")
    List<ResponsePost> selectCidsByStudentId(String studentId);

    /**
     * 根据学号查询回复信息总数
     * @param studentId
     * @return
     */
    @Select("select count(*) from response_post where student_id = #{studentId}")
    Long getTotalByStudentId(String studentId);
}
